//package com.zl.zsk.config;
//
//import com.google.common.collect.Maps;
//import org.springframework.amqp.core.*;
//import org.springframework.beans.factory.annotation.Qualifier;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//
//import java.util.HashMap;
//import java.util.Map;
//
///**
// * @author lxb
// * @version 1.0.0
// * @desc: rabbitmq的配置类
// * 声明了两个交换器，一个是正常的交换器，一个是死信交换器
// * 正常交换器下有两个正常的业务性队列a和b，a和b通过各自的路由键绑定到了该正常的交换器中
// * 同时，这两个正常的业务性队列与同一个死信交换器进行了绑定，通过各自己的死信路由键进行绑定
// * 死信交换器下有两个死信队列，是通过设置的路由键进行的绑定
// * @date 2020-03-18 15:07
// */
//@Configuration
//public class RabbitMqConfig {
//    //fanout交换器名称
//    public static final String LXB_FANOUT_EXCHANGE = "lxb.fanout.exchange";
//    //a业务的队列名称
//    public static final String LXB_A_BUSINESS_QUEUE = "lxb.a.business.queue";
//    //b业务的队列名称
//    public static final String LXB_B_BUSINESS_QUEUE = "lxb.b.business.queue";
//    //死信交换机
//    public static final String LXB_DEAD_LETTER_EXCHANGE = "lxb.dead.letter.exchange";
//    //a队列的死信路由key
//    public static final String LXB_DEAD_LETTER_A_ROUTING_KEY = "lxb.dead.letter.a.routingkey";
//    //b队列的死信路由key
//    public static final String LXB_DEAD_LETTER_B_ROUTING_KEY = "lxb.dead.letter.b.routingkey";
//    //死信队列a
//    public static final String LXB_DEAD_LETTER_A_QUEUE = "lxb.dead.letter.a.queue";
//    //死信队列b
//    public static final String LXB_DEAD_LETTER_B_QUEUE = "lxb.dead.letter.b.queue";
//
//    //业务交换机
//    @Bean("fanoutExchange")
//    public FanoutExchange fanoutExchange() {
//        return new FanoutExchange(LXB_FANOUT_EXCHANGE);
//    }
//
//    //死信交换机
//    @Bean("deadLetterExchange")
//    public DirectExchange deadLetterExchange() {
//        return new DirectExchange(LXB_DEAD_LETTER_EXCHANGE);
//    }
//
//    //业务a的队列的创建
//    @Bean("businessAQueue")
//    public Queue businessAQueue() {
//        Map<String, Object> args = new HashMap<>(2);
////       x-dead-letter-exchange    这里声明当前队列绑定的死信交换机
//        args.put("x-dead-letter-exchange", LXB_DEAD_LETTER_EXCHANGE);
////       x-dead-letter-routing-key  这里声明当前队列的死信路由key
//        args.put("x-dead-letter-routing-key", LXB_DEAD_LETTER_A_ROUTING_KEY);
//        return QueueBuilder.durable(LXB_A_BUSINESS_QUEUE).withArguments(args).build();
//    }
//
//    //业务b的队列的创建
//    @Bean("businessBQueue")
//    public Queue businessBQueue() {
//        Map<String, Object> args = new HashMap<>(2);
////       x-dead-letter-exchange    这里声明当前队列绑定的死信交换机
//        args.put("x-dead-letter-exchange", LXB_DEAD_LETTER_EXCHANGE);
////       x-dead-letter-routing-key  这里声明当前队列的死信路由key
//        args.put("x-dead-letter-routing-key", LXB_DEAD_LETTER_B_ROUTING_KEY);
//        return QueueBuilder.durable(LXB_B_BUSINESS_QUEUE).withArguments(args).build();
//    }
//
//    //死信队列A
//    @Bean("deadLetterAQueue")
//    public Queue deadLetterAQueue() {
//        return new Queue(LXB_DEAD_LETTER_A_QUEUE);
//    }
//
//    //死信队列B
//    @Bean("deadLetterBQueue")
//    public Queue deadLetterBQueue() {
//        return new Queue(LXB_DEAD_LETTER_B_QUEUE);
//    }
//
//    //将a队列绑定到正常的fanout交换器
//    @Bean
//    public Binding businessBindingA(@Qualifier("businessAQueue") Queue queue,
//                                    @Qualifier("fanoutExchange") FanoutExchange exchange) {
//        return BindingBuilder.bind(queue).to(exchange);
//    }
//
//    //将b队列绑定到正常的fanout交换器
//    @Bean
//    public Binding businessBindingB(@Qualifier("businessBQueue") Queue queue,
//                                    @Qualifier("fanoutExchange") FanoutExchange exchange) {
//        return BindingBuilder.bind(queue).to(exchange);
//    }
//
//    //死信队列a绑定到死信交换器，是通过路由键a来绑定的
//    @Bean
//    public Binding deadLetterBindingA(@Qualifier("deadLetterAQueue") Queue queue,
//                                      @Qualifier("deadLetterExchange") DirectExchange exchange) {
//        return BindingBuilder.bind(queue).to(exchange).with(LXB_DEAD_LETTER_A_ROUTING_KEY);
//    }
//
//    //通过路由键b来将死信队列b绑定到死信交换器
//    @Bean
//    public Binding deadLetterBindingB(@Qualifier("deadLetterBQueue") Queue queue,
//                                      @Qualifier("deadLetterExchange") DirectExchange exchange) {
//        return BindingBuilder.bind(queue).to(exchange).with(LXB_DEAD_LETTER_B_ROUTING_KEY);
//    }
//
//    @Value("${mq.second.kill.dead.queue}")
//    private String deadQueue;
//    @Value("${mq.second.kill.dead.exchange}")
//    private String deadExchange;
//    @Value("${mq.second.kill.dead.routing.key}")
//    private String deadRoutingKey;
//    @Value("${mq.second.kill.dead.real.queue}")
//    private String deadRealHandleQueue;
//    @Value("${mq.second.kill.dead.real.exchange}")
//    private String deadRealHandleExchange;
//    @Value("${mq.second.kill.dead.real.routing.key}")
//    private String deadRealHandleRoutingKey;
//
//    //    //普通队列
////    @Bean
////    public Queue deadQueue() {
////        Map<String, Object> map = Maps.newHashMapWithExpectedSize(2);
////        map.put("x-dead-letter-exchange", deadRealHandleExchange);
////        map.put("x-dead-letter-routing-key", deadRealHandleRoutingKey);
//////        return new Queue(deadQueue,true,false,false,map);
////        return QueueBuilder.durable(deadQueue).withArguments(map).build();
////    }
////普通队列
//    @Bean
//    public Queue deadQueue() {
//        Map<String, Object> map = Maps.newHashMapWithExpectedSize(2);
//        map.put("x-dead-letter-exchange", deadExchange);
//        map.put("x-dead-letter-routing-key", deadRealHandleRoutingKey);
////        return new Queue(deadQueue,true,false,false,map);
//        return QueueBuilder.durable(deadQueue).withArguments(map).build();
//    }
//
//    //普通交换机
//    @Bean
//    public DirectExchange deadExchange() {
//        return new DirectExchange(deadExchange, true, false);
//    }
//
//    //普通队列和普通交换机绑定
//    @Bean
//    public Binding successKillBinding() {
//        return BindingBuilder.bind(deadQueue()).to(deadExchange()).with(deadRoutingKey);
//    }
//
//    //死信队列
//    @Bean
//    public Queue realHandleQueue() {
//        return new Queue(deadRealHandleQueue, true);
//    }
//
//    //    //死信交换器
////    @Bean
////    public DirectExchange realHandleExchange(){
////        return new DirectExchange(deadRealHandleExchange,true,false);
////    }
//    //死信队列和死信交换器的绑定
////    @Bean
////    public Binding realHandleBinding(){
////        return BindingBuilder.bind(realHandleQueue()).to(realHandleExchange()).with(deadRealHandleRoutingKey);
////    }
//    @Bean
//    public Binding realHandleBinding() {
//        return BindingBuilder.bind(realHandleQueue()).to(deadExchange()).with(deadRealHandleRoutingKey);
//    }
//
//
////    @Bean
////    public RabbitTemplate rabbitTemplate(ConnectionFactory connectionFactory){
////        RabbitTemplate rabbitTemplate = new RabbitTemplate(connectionFactory);
////        rabbitTemplate.setMessageConverter(new Jackson2JsonMessageConverter());
////        return rabbitTemplate;
////    }
//}
